package com.ymnet.mynetframewrok;

import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.ymnet.myretrofit.FileCallBack;
import com.ymnet.myretrofit.bean.User;
import com.ymnet.myretrofit.RetrofitClient;

import java.util.HashMap;
import java.util.List;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void onStart() {
        super.onStart();
        requestData();
        download();
        fortune();
    }

    private void fortune() {
        /**
         * appid=
         */
        RetrofitClient.getInstance(this)
                .builder("https://api.weixin.qq.com/")
                .fortune()
                .enqueue(new Callback<Object>() {
                    @Override
                    public void onResponse(Call<Object> call, Response<Object> response) {
                        Log.d("MainActivity", "response.code():" + response.code());
                        Object body = response.body();
                        Log.d("MainActivity", response.body().toString());
                    }

                    @Override
                    public void onFailure(Call<Object> call, Throwable t) {
                        t.printStackTrace();
                    }
                });
    }

    private void download() {
        RetrofitClient.getInstance(this)
                .builder()
                .downloadTest()
                .enqueue(new FileCallBack(this, Environment.getExternalStorageDirectory().getAbsolutePath(), "downloadtext") {
                    @Override
                    public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                        super.onResponse(call, response);
                    }

                    @Override
                    public void inProgress(float progress) {

                    }

                    @Override
                    public void onFailure(Call<ResponseBody> call, Throwable t) {

                    }
                });

    }

    private void requestData() {
        RetrofitClient.getInstance(this)
                .builder()
                .groupList(2, new HashMap<String, String>())
                .enqueue(new Callback<List<User>>() {
                    @Override
                    public void onResponse(Call<List<User>> call, Response<List<User>> response) {

                    }

                    @Override
                    public void onFailure(Call<List<User>> call, Throwable t) {

                    }
                });
    }


}
